package com.lsq.tomcat;

import javax.servlet.Servlet;
import java.util.HashMap;
import java.util.Map;

/**
 * @author lsq
 * @description TODO
 * @date 2023/9/19
 */
public class Context {
    private String appName;
    private Map<String, Servlet> urlPatternMap = new HashMap<>();

    public Context(String appName) {
        this.appName = appName;
    }

    public void addUrlPattern(String urlPattern, Servlet servlet) {
        urlPatternMap.put(urlPattern, servlet);
    }

    public Servlet getUrlPattern(String urlPattern) {
        for (String key : urlPatternMap.keySet()) {
            if (key.contains(urlPattern)) {
                return urlPatternMap.get(key);
            }
        }
        return null;
    }
}
